import axios from 'axios'

// create an axios instance
const service = axios.create({
  baseURL: process.env.VUE_APP_URL, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

const request = (url, data = {}, method = 'get') => {
  const _data = {
    'get': 'params',
    'post': 'data',
    'delete': 'params',
    'put': 'data',
    'patch': 'data'
  }
  return service({
    url: url,
    method: method,
    [_data[method.toLowerCase()]]: data,
    headers: {
      token: '63ddfda3d40aa'
    }
  })
}

export default request
